package com.railway.servlet;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.railway.service.UserService;
import com.railway.service.impl.UserServiceImpl;
@WebServlet("/DelBatchUser.do")
/**
 * @author 
 *批量删除（逻辑）
 */
public class DelBatchUserServlet extends HttpServlet{

	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		doPost(req, resp);
	}

	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		resp.setCharacterEncoding("UTF-8");
		resp.setContentType("application/json");
		req.setCharacterEncoding("UTF-8");
		UserService us = new UserServiceImpl();
		String[] usId = req.getParameterValues("dataId");
		int[] usIds = new int[usId.length];
		if(usIds.length == 0) {
			return ;
		}
		int msg;
		for (int i = 0; i < usId.length; i++) {
			usIds[i] = Integer.parseInt(usId[i]);
			msg = us.deleteUser(usIds[i]);
			if(msg == 1) {
				resp.getWriter().print("success");
			}
		}
	}
	

}
